package ltd.itlover.yqblog.utils;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;



import org.litepal.crud.DataSupport;

import ltd.itlover.yqblog.application.MyApplication;
import ltd.itlover.yqblog.entity.User;

public class TokenUtil {
    public static String token = null;
    public static String getToken(){


//            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MyApplication.context);
//
//            String currentUserEmail = sharedPreferences.getString("currentUserEmail", null);

            //从数据库中找到当前登录的账户

            if(token != null){
                return token;
            }

            User currentUser = null;

            try {
                currentUser = DataSupport.findLast(User.class);
            }catch (Exception e){

            }

            if (currentUser != null){
                token = currentUser.getToken();
            }

            return token;

    }

    public static void setToken(String token1){
        token = token1;
    }
    public static void clearToken(){
        token = null;
        DataSupport.deleteAll(User.class);
    }

    public static String getImgDomain(){
        return "http://avatar.itlover.ltd/";
    }
}
